package com.leona.splashlibrary.utils;

import com.leona.splashlibrary.R;

import java.lang.reflect.Field;
import java.util.Random;

/**
 * Created by admin on 2018/4/24.
 * 用于获取启动页图片的工具类
 */

public class SplashUtils {

    /**
     * 产生一个随机数
     *
     * @param min
     * @param max
     * @return
     */
    public static int getRandom(int min, int max) {
        Random random = new Random();
        int num = random.nextInt(max) % (max - min + 1) + min;
        return num;
    }

    /**
     * Android根据图片名称加载Drawable里面的图片并且显示
     *
     * @param name
     * @return
     */
    public static int getImages(String name) {
        Class drawable = R.drawable.class;
        Field field = null;
        try {
            field = drawable.getField(name);
            int images = field.getInt(field.getName());
            return images;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}
